package chapter7;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则匹配字符串的起始位置和结束位置的索引
 */
public class StartEnd {
    public static void main(String[] args) {
        String regStr = "Java is very easy!";
        System.out.println("目标字符串是:" + regStr);
        Matcher matcher = Pattern.compile("\\w+").matcher(regStr);
        while (matcher.find()) {
            System.out.println(matcher.group() + "子串的起始位置:" + matcher.start()
            + ", 其结束位置:" + matcher.end());
        }
    }
}
